<template>
    <div id="Statistical_Into">
      <el-card class="box-card">
        <div class="user-profile">
          <div class="user-avatar" @click="dialogVisibleuser=true" :style="{ backgroundImage: 'url(' + writerInfo.avatar + ')' }"></div>
          <div class="name">
            {{ writerInfo.nickname }}
            <!-- 如果is_sign为真（或存在且为1），则显示签约作者标签 -->
            <span v-if="writerInfo.is_sign === 1" class="tag">签约作者</span>
            <!-- 如果is_sign为假（或不存在，或不为1），则显示申请签约按钮 -->
            <button v-else @click="showApplyDialog()" class="apply-button">申请签约</button>

          </div>
          <div class="signature">{{ writerInfo.sign }}</div>
        </div>

      </el-card>

      <!-- 弹出框 -->
      <el-dialog title="申请签约"  :width="this.$store.state.dialogWidth" :visible.sync="showDialog">
        <el-form :model="formData" ref="formRef">
          <el-form-item label="手机号" prop="phoneNumber">
            <el-input v-model="formData.real_phone" placeholder="请输入真实手机号"></el-input>
          </el-form-item>
          <el-form-item label="微信号" prop="wechatNumber">
            <el-input v-model="formData.real_wx" placeholder="请输入真实微信号"></el-input>
          </el-form-item>
          <div class="dialog-footer" style="text-align: right; margin: 20px;">
            <el-button @click="showDialog = false" size="small">取 消</el-button>
            <el-button type="primary" @click="confirm" size="small">确 定</el-button>
          </div>
        </el-form>
      </el-dialog>
      <el-dialog
          title="个人信息"
          :visible.sync="dialogVisibleuser"
          :width="this.$store.state.dialogWidth">
        <el-row :gutter="20">
          <el-col :span="this.$store.state.elColNum">
            <el-form ref="form" :label-width="this.$store.state.labelWidth" size="small">
              <el-form-item label="新笔名">
                <el-input v-model="homeform.pen_name"></el-input>
              </el-form-item>
            </el-form>
          </el-col>
        </el-row>
        <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisibleuser = false" size="small">取 消</el-button>
    <el-button type="primary" @click="updateUser" size="small">确 定</el-button>
  </span>
      </el-dialog>
        <el-breadcrumb style="margin-top: 16px;" separator="/">
            <el-breadcrumb-item>作品管理</el-breadcrumb-item>
        </el-breadcrumb>
        <el-card class="box-card">
            <el-form ref="form" :model="searchForm" label-width="80px" :inline="true" size="small" class="admin_from">
                <el-form-item>
                    <el-button type="primary" size="small" @click="addRecharge">添加作品</el-button>
                </el-form-item>
            </el-form>
            <el-table
                    size="small"
                    :data="tableData"
                    border
                    style="width: 100%">
                <el-table-column
                        type="index"
                        label="#"
                        width="50">
                </el-table-column>
                <el-table-column
                        prop="coverpic"
                        label="封面"
                        width="122">
                    <template slot-scope="scope">
                        <p style="text-align: center">
                            <img :src="scope.row.coverpic" width="80" alt="">
                        </p>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="title"
                        label="书名">
                </el-table-column>
                <el-table-column
                        prop="word_count"
                        label="总字数">
                </el-table-column>
                <el-table-column
                        prop="iswz"
                        label="进度">
                    <template slot-scope="scope">
                        <span v-if="scope.row.iswz==1">连载</span>
                        <span v-if="scope.row.iswz==2">完结</span>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="address"
                        label="审核状态">
                    <template slot-scope="scope">
                        <span v-if="scope.row.status==''">已发布</span>
                        <span v-if="scope.row.status=='draft'">草稿</span>
                        <span v-if="scope.row.status=='auditing'">审核中</span>
                        <span v-if="scope.row.status=='failed'">审核失败</span>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="address"
                        label="操作"
                        width="300">
                    <template slot-scope="scope">
                        <p style="text-align: center">

                            <el-button type="info" plain size="small" @click="look(scope.row.id)" v-if="scope.row.status=='' || scope.row.anid">小说章节</el-button>

                            <el-button type="primary" plain size="small" @click="edit(scope.row.id, scope.row.version)" v-if="scope.row.status!='auditing'">修改</el-button>
                            <el-button type="text" plain size="small"  v-if="scope.row.status=='auditing'">审核中，不可修改</el-button>
                        </p>
                    </template>
                </el-table-column>
            </el-table>
<!--            <div class="el-pagination">-->
<!--                <el-pagination-->
<!--                        background-->
<!--                        @size-change="changeSize"-->
<!--                        @current-change="changeCurrent"-->
<!--                        :current-page="params.pagenum"-->
<!--                        :page-sizes="[10, 20, 30, 40]"-->
<!--                        :page-size="params.pagesize"-->
<!--                        :total="params.totals"-->
<!--                        :layout="this.$store.state.paginationLayout">-->
<!--                </el-pagination>-->
<!--            </div>-->
        </el-card>
        <!--            新增或编辑-->
        <el-dialog :title="formTitle" :width="this.$store.state.dialogMaxWidth" :visible.sync="visible">
            <novelDetail v-if="visible" @closeDatails="closeDatails" :bookId="bookId"></novelDetail>
        </el-dialog>



    </div>
</template>

<script>
  import novelDetail from '../../components/novel_list/novel_list'

  export default {
    name: "Statistical_Into",
    components: {novelDetail},
    data() {
      return {
        params: {
          pagenum: 1,
          pagesize: 10,
          totals: 0,
        },
        showDialog: false,
        formData: {
          real_phone: '',
          real_wx: '',
        },
        dialogVisibleuser: false,
        tableData: [],
        fromTitle: '',
        visible: false,
        btype: 2,
        title: '',
        author: '',
        searchForm: {
          isrecommend: '',
          status: '',
          ishow: '',
          issex: '',
        },
        formTitle: '',
        formTitle2:'',
        bookId: '',
        browsevisible: false,
        writerInfo: [],
        homeform: {
          name: '',
          pen_name: '',
          phone: '',
          mail:'',
        },

      }
    },

    created() {
      this.getList();
      this.getUserInfo();
    },
    methods: {
      getUserInfo() {
        this.$axios.post('writer/writer/get_info').then((res) => {
          this.writerInfo = res.data;
        });
      },
      showApplyDialog() {
        this.showDialog = true

      },
      updateUser() {
        this.$axios.post('writer/writer/update', this.homeform).then((res) => {
          this.$message.success('成功');
          this.dialogVisibleuser = false;
          window.location.reload();
        });
      },
      getList() {
        let data = {
          page: this.params.pagenum,
          page_size: this.params.pagesize,
          title: this.title,
          author: this.author,
          isrecommend: this.searchForm.isrecommend,
          status: this.searchForm.status,
          ishow: this.searchForm.ishow,
          issex: this.searchForm.issex
        };
        this.$axios.post("writer/novel/index", data).then((res) => {
          console.log(res.data);
          this.params.totals = res.data.count;
          this.tableData = res.data.list;
        });
      },
      confirm: function() {


        //sign-application
        this.$axios.post("writer/sign-application", this.formData).then((res) => {
          this.$message.success('提交申请成功！稍后会有工作人员联系您哦');

        });
        // 关闭弹出框
        this.showDialog = false;
      },
      // 每页显示多少条
      changeSize(val) {
        this.params.pagesize = val;
        this.getList();
      },
      // 当前显示的页数
      changeCurrent(val) {
        this.params.pagenum = val;
        this.getList();
      },
      addRecharge() {
        this.$router.push({
          path: '/novel_details'
        })
      },
      edit(id, version) {
        this.id = id;


        this.$router.push({
          path: '/novel_details',
          query: {
            id: id,
            version: version
          }
        })
      },
      browsenote(chaps) {

        this.formTitle2 = '浏览编辑记录';

        let data = {
          anid: this.anid,
          index: chaps,
          page: 1,
          page_size: 100,
        };
        this.$axios.post("admin/chapter/browse_auditnote", data).then((res) => {

          this.tableData_sh = res.data;

        });

        this.browsevisible = true;
      },
      look(id) {
        this.$router.push({
          path: '/novel_diversity',
          query: {
            id: id
          }
        })
      },
      onPush(version) {
        this.$confirm('是否提交审核？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$axios.post("writer/novel/push", {version: version}).then((res) => {
            this.$message.success('提交成功');
            this.getList();
          });
        })
      },
      remove(id) {
        this.$confirm('确定要进行操作, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$axios.del('writer/novel/' + id, '').then((res) => {
            this.$message.success('删除成功!');
            this.getList();
          });
        }).catch(() => {

        });
      },
      closeDatails(data) {
        this.visible = data;
        this.getList();
      }
    }
  }
</script>

<style scoped>
.user-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%; /* 设置为圆形 */
  overflow: hidden; /* 实际上对于背景图片无效，但保留以防其他用途 */
  /* 移除 display: flex; 及其子属性，因为它们对于背景图片无效 */
  background-size: cover; /* 覆盖整个div，但可能会裁剪图片 */
  background-position: center; /* 确保图片的中心部分被显示 */
  background-repeat: no-repeat; /* 防止图片重复 */
  background-color: #ccc; /* 示例背景色，当图片未加载或URL错误时显示 */
}

.user-profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center; /* 确保用户名和签名都居中 */
}
.tag, .apply-button {
  /* 假设你希望它们都以按钮的形式展示 */
  display: inline-block;
  padding: 4px 8px;
  margin-left: 5px; /* 使得标签或按钮与昵称之间有一些间距 */
  /* 仅为申请签约按钮添加的特殊样式（如果需要的话） */
  background-color: #007bff; /* 蓝色背景 */
  color: white; /* 白色文字 */
  font-size: 12px;
  font-weight: lighter;
  border-radius: 4px; /* 圆角 */
  cursor: pointer; /* 鼠标悬停时显示指针 */
}

.apply-button {
  /* 仅为申请签约按钮添加的特殊样式（如果需要的话） */
  background-color: #007bff; /* 蓝色背景 */
  color: white; /* 白色文字 */
  padding: 4px 8px;
  margin-left: 5px; /* 使得标签或按钮与昵称之间有一些间距 */
  border: white;
}
.name {
  font-weight: bold; /* 用户名加粗 */
  margin: 10px 0; /* 上下边距 */
}

.signature {
  font-size: 0.8rem; /* 签名字体变小 */
  color: #666; /* 签名字体变灰 */
  margin: 5px 0; /* 稍微减少签名的上下边距 */
}

</style>